/**
 * Created by zyy on 15/4/28.
 */
if (typeof jQuery == 'undefined') {
    //为zepto和jquery进行整合。
    jQuery = Zepto;

    jQuery.noop || (jQuery.noop = function() {});
}

(function($) {
    /*$.sub = function () {
        function a(b, c) {
            return new a.fn.init(b, c);
        }

        $.extend(!0, a, this),
            a.superclass = this,
            a.fn = a.prototype = this(),
            a.fn.constructor = a,
            a.sub = this.sub,
            a.fn.init = function c(c, d) {
                return d && d instanceof p && !(d instanceof a) && (d = a(d)),
                    $.fn.init.call(this, c, d, b)
            },
            a.fn.init.prototype = a.fn
        var b = a(e);
        return a;
    };*/

    // add common module namespace
    window.App = $.extend({}, window.App, {
        common: {
            modules: {}
        },
        modules: {}
    });

    template.draw = function(tpl, data) {
        return template.render(tpl)(data);
    }

    $(document).ajaxError(function(e, xhr, ajaxSettings, thrownError) {
        if (xhr.status === 404) {
            //window.location.href = App.modules.util.rootPath + '/error/404'
        }
        App.common.smallnote(xhr.responseText || '系统异常，请重试', {
            pattern: 'error'
        });
    });

    $(document).ajaxSuccess(function(e, xhr, ajaxSettings) {

        var data = JSON.parse(xhr.responseText);
        if (data.code != 200) {
            App.common.smallnote(data.message, {
                pattern: 'error'
            });
        }
    });

    $.ajaxSetup && $.ajaxSetup({
        dataType: 'json',
        type: 'get'
    });
})(jQuery);
